﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Reflection;
using System.Collections;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using System.Text;

namespace YunShop_WebAPI
{
    public class Service
    {
        private const string mSuccess = "{'result':'success','data':'提交成功'}";
        private const string mErrJson = "{'result':'failure','data':[],'msg':'保存失败'}";

        /// <summary>
        /// 参数设置
        /// </summary>
        public class SqlParameterList
        {
            List<SqlParameter> list_Para = new List<SqlParameter>();
            public SqlParameterList()
            {
                list_Para.Clear();
            }

            public SqlParameter GetParam(string name)
            {
                for(int i=0;i<list_Para.Count;i++)
                {
                    if (list_Para[i].ParameterName.Equals(name))
                        return list_Para[i];
                }
                return null;
            }
            /// <summary>
            /// 添加參數
            /// </summary>
            /// <param name="Parameter">參數定義</param>
            /// <param name="value">參數值</param>
            public void Add(SqlParameter Parameter, object value)
            {
                list_Para.Add(Parameter);
                list_Para.Last<SqlParameter>().Value = value;
            }

            /// <summary>
            /// 添加參數
            /// </summary>
            /// <param name="parameterName"></param>
            /// <param name="dbType"></param>
            /// <param name="size"></param>
            /// <param name="value"></param>
            public void Add(string parameterName, SqlDbType dbType, int size, object value)
            {
                list_Para.Add(new SqlParameter(parameterName, dbType, size));
                list_Para.Last<SqlParameter>().Value = value;
            }
            
            /// <summary>
            /// 添加參數
            /// </summary>
            /// <param name="parameterName"></param>
            /// <param name="dbType"></param>
            /// <param name="value"></param>
            public void Add(string parameterName, SqlDbType dbType, object value)
            {
                list_Para.Add(new SqlParameter(parameterName, dbType));
                list_Para.Last<SqlParameter>().Value = value;
            }

            /// <summary>
            /// 返回參數數組
            /// </summary>
            /// <returns></returns>
            public SqlParameter[] Get_List()
            {
                return list_Para.ToArray();
            }
        }

        //程序结束
    }
}